package com.controlador;

import java.io.File;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JOptionPane;

import com.util.Constantes;

import jxl.*;
import jxl.write.*;
import jxl.write.biff.RowsExceededException;
 
public class JavaExcelWriter {
 
  public void escribeExcel(Vector<?> v, String[] enc){
 
	  System.out.println("escribe!!!");
	  
	  try {
          File exlFile = new File(Constantes.ARCHIVO_EXCEL_TEMPORAL);
          WritableWorkbook writableWorkbook = Workbook
                  .createWorkbook(exlFile);

          WritableSheet writableSheet = writableWorkbook.createSheet(
                  "Sheet1", 0);
	  
	  
	  int tamanio = v.size();
	  
	  for(int temp=0;temp < enc.length;temp++ )
		  {
		   	writableSheet.addCell((WritableCell) new jxl.write.Label(temp,0,enc[temp]));
		  }
	   
	  
	  
	  for (Integer i=0;i<tamanio;i++)
	  {
		  Vector<?> vec = (Vector<?>) v.elementAt(i);
		   int tam = vec.size();
		  
		   for (int j=0;j<tam;j++)
		   {
			   writableSheet.addCell((WritableCell) new jxl.write.Label(j,i+1,(String) vec.elementAt(j)));
		   }
	  }
	  
	  writableWorkbook.write();
      writableWorkbook.close();
      JOptionPane.showMessageDialog(null, "Export Correct");
	  
	  	} catch (IOException e) {
	  		e.printStackTrace();
	  	} catch (RowsExceededException e) {
	  		e.printStackTrace();
	  	} catch (WriteException e) {
	  		e.printStackTrace();
	  	}
	  
     
    }
 
}